import java.util.*;
import java.io.*;
public class Main{
    static int []fa = null;
    static int find(int x){
        return fa[x] = fa[x]==x ? x : find(fa[x]);
    }
    public static void main(String[]args){
        Scanner reader = new Scanner(System.in);
        int n = reader.nextInt();
        int m = reader.nextInt();
        fa = new int[n+1];
        for(int i=1;i<=n;i++) fa[i]=i;
        while(m-->0){
            int z = reader.nextInt();
            int x = reader.nextInt();
            int y = reader.nextInt();
            if(z==1) fa[find(x)] = find(y);
            else System.out.println(find(x)==find(y) ? "Y" : "N");
        }
        reader.close();
    }
}